package com.new_wear.project.homepage.controller;

import com.new_wear.framework.web.controller.BaseController;
import com.new_wear.framework.web.page.TableDataInfo;
import com.new_wear.project.article.article.domain.CstArticle;
import com.new_wear.project.article.article.service.ICstArticleService;
import com.new_wear.project.system.access.domain.CstVolunteerGroupAccess;
import com.new_wear.project.system.access.service.ICstVolunteerGroupAccessService;
import com.new_wear.project.system.cst_user.domain.CstUser;
import com.new_wear.project.system.cst_user.service.ICstUserService;
import com.new_wear.project.homepage.domain.Homepage;
import com.new_wear.project.system.video.domain.CstVideo;
import com.new_wear.project.system.video.service.ICstVideoService;
import com.new_wear.project.system.visits.domain.CstVisits;
import com.new_wear.project.system.visits.service.ICstVisitsService;
import com.new_wear.project.system.volunteer.domain.CstVolunteer;
import com.new_wear.project.system.volunteer.service.ICstVolunteerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ZhangRenpeng
 * @Description:
 * @date 2020/1/10 13:26
 */
@Controller
@RequestMapping("/system/homepage")
public class HomepageController extends BaseController {

    @Autowired
    private ICstArticleService cstArticleService;
    @Autowired
    private ICstVideoService cstVideoService;
    @Autowired
    private ICstUserService cstUserService;
    @Autowired
    private ICstVolunteerService cstVolunteerService;
    @Autowired
    private ICstVisitsService cstVisitsService;
    @Autowired
    private ICstVolunteerGroupAccessService cstVolunteerGroupAccessService;

    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo homepage(){
        ArrayList<Homepage> homepageList = new ArrayList<>();
        List<CstArticle> cstArticlesList = cstArticleService.selectCstArticleList(new CstArticle());//文章
        List<CstVideo> cstVideoList = cstVideoService.selectCstVideoList(new CstVideo());//视频数量
        List<CstUser> cstUserList = cstUserService.selectCstUserList(new CstUser());//用户数量
        List<CstVolunteer> volunteerList = cstVolunteerService.selectCstVolunteerList(new CstVolunteer());//志愿者
        List<CstVisits> cstVisitsList = cstVisitsService.selectCstVisitsList(new CstVisits());//访问总数量
        List<CstVolunteerGroupAccess> cstVolunteerGroupAccesses = cstVolunteerGroupAccessService.selectCstVolunteerGroupAccessList(new CstVolunteerGroupAccess());//团体
        Homepage homepage = new Homepage();
        homepage.setInformationNumber(cstArticlesList.size());
        homepage.setVideoNumber(cstVideoList.size());
        homepage.setUserNumber(cstUserList.size());
        homepage.setVolunteerNumber(volunteerList.size());
        homepage.setVisitNumber(cstVisitsList.size());
        homepage.setGroupNumber(cstVolunteerGroupAccesses.size());
        homepageList.add(homepage);
        return getDataTable(homepageList);
    }
}

